package tsing.javase.thread;

import com.alibaba.fastjson.JSON;


import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class Demo {


    private static int workerCountOf(int c)  {
        return c & 5;  //&：按位与，把& 左右两侧的int 转为二进制，在按位取与（1为true,0为false, true 与true为ture, true 与false为false）
    }

    public static void main(String[] args) {



        //for Test
//        for(;;){  // = while(true)
//            System.out.println("I am comming");
//        }
//
//        System.out.println(workerCountOf(6));

//        ifMethod();

//        testContinue();

//        testBreak();


/*        String str = "Java";

        System.out.printf("Hello ,%s\n",str);

        char c = 'a';
        System.out.println(c);


        new Thread() {
            @Override
            public void run() {
                    System.out.println(Thread.currentThread().getName());
            }
        }.start();*/


//        method1();

/*        String str = "{\"2e105fd95b0b42248c994690ea987751_8.00_7.55\":200,\"d27215c26cf54f4e90503de2d2152aa3_8.00_7.55\":100}";
        Map map = JSON.parseObject(str, Map.class);
        Set set = map.keySet();
        for (Object o : set) {
            String key = o.toString();
            String[] s = key.split("_");
            System.out.println("含税价："+s[1]);
            Object o1 = map.get(key);
            System.out.println("剩余数量"+o1);

        }*/

       /* Map<String,Long> map = new HashMap<>();
        System.out.println(map.get("1"));*/

        // 获取当前日期
        LocalDate today = LocalDate.now();

        // 输出三个月前的同一天
        LocalDate threeMonthsAgo = today.minusMonths(3);

        // 定义日期格式为 yyyymmdd
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");

        // 使用 DateTimeFormatter 将日期格式化
        String formattedDate = threeMonthsAgo.format(formatter);

        String td =today.format(formatter);

        System.out.println("今天的日期是：" + today);
        System.out.println("三个月前的同一天是：" + threeMonthsAgo);

        System.out.println(getDateListBetweenTwoDates(formattedDate, td));

    }


    private static List<String> getDateListBetweenTwoDates(String startDate, String endDate) {
        List<String> dateList = new ArrayList<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        LocalDate start = LocalDate.parse(startDate, formatter);
        LocalDate end = LocalDate.parse(endDate, formatter);
        while (!start.isAfter(end)) {
            dateList.add(start.format(formatter));
            start = start.plusDays(1);
        }
        return dateList;
    }


    private static void method1() {
        Map<String, List<String>> map  = new HashMap<>();
        for (int i = 0; i <3 ; i++) {
            ArrayList<String> list = new ArrayList<>();
            String s = "";
            switch(i){
                case 0:
                  s = "Java";
                  break;
                case 1:
                    s = "Python";
                    break;
                case 2:
                    s = "C";
                    break;
            }
            for (int j = 0; j < 3; j++) {
                list.add(s+j);
            }
            map.put(String.valueOf(i),list);
        }

        System.out.println(JSON.toJSONString(map));

        Set<Map.Entry<String, List<String>>> entries = map.entrySet();
        for (Map.Entry<String, List<String>> entry : entries) {
            ArrayList<String> list = new ArrayList<>();
            List<String> value = entry.getValue();
            String key = entry.getKey();
            Integer num = Integer.valueOf(key);
            String s  = "";
            switch (num){
                case 0:
                    s = "Java_new";
                    break;
                case 1:
                    s = "Python_new";
                    break;
                case 2:
                    s = "C_new";
                    break;
            }
            for (int j = 0; j < 3; j++) {
                list.add(s+j);
            }

            entry.setValue(list);
        }

        System.out.println(JSON.toJSONString(map));
    }


    public static  void ifMethod(){
        if (5 < 10) {
            if (1<2)
                return;
            int a =+ 5;
            System.out.println(5);
        }

    }




    //retry标记语法,continue retry 类似于go to
    public static void testContinue() {
        retry:
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 5; j++) {
                System.out.print(j + ",");
                if (j == 3) {
                    continue retry;
                }
            }
            System.out.println();
        }
    }


    //retry标记语法 :  break ,任然是终止循环
    public static void testBreak() {
        retry:
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 5; j++) {
                System.out.print(j + ",");
                if (j == 3) {
                    break retry;
                }
            }
            System.out.println();
        }
    }



}
